//
//  Cell_Course.m
//  yjw-winner
//
//  Created by Kae on 2018/9/5.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "Cell_Course.h"
#import "JudgeStarsView.h"

@interface Cell_Course ()<UIScrollViewDelegate> {}

// cell 0
@property (weak, nonatomic) IBOutlet UILabel *titleLabel0;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel0;

// cell 1

@property (weak, nonatomic) IBOutlet UILabel *titleLabel1;
@property (weak, nonatomic) IBOutlet UILabel *timesLabel1;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView1;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel1;
@property (weak, nonatomic) IBOutlet UILabel *classNameLabel1;
@property (weak, nonatomic) IBOutlet JudgeStarsView *starsView;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel1;
@property (weak, nonatomic) IBOutlet UIButton *judgeButton1;
@property (weak, nonatomic) IBOutlet UIButton *lookforButton1;

// cell 2
@property (weak, nonatomic) IBOutlet UILabel *titleLabel2;
@property (weak, nonatomic) IBOutlet UILabel *lecturerLabel2;
@property (weak, nonatomic) IBOutlet UILabel *contextLabel2;

// cell 3

@property (weak, nonatomic) IBOutlet UILabel *titleLabel3;

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@property (weak, nonatomic) IBOutlet UIPageControl *paageControl;


@property (nonatomic, copy) CallBackCellCourseBlock block;
@property (nonatomic, strong) id model;
@end
@implementation Cell_Course
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        NSString *str = [reuseIdentifier substringFromIndex:reuseIdentifier.length - 1];
        NSInteger index = [str integerValue];
        self = (Cell_Course *)[[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([Cell_Course class]) owner:self options:nil] objectAtIndex: index];
    }
    return self;
}
- (void)refreshWithModel:(id)model CallBackBlock:(CallBackCellCourseBlock)block {
    self.model = model;
    self.block = block;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    if (self.judgeButton1) {
        self.judgeButton1.layer.masksToBounds = YES;
        self.judgeButton1.layer.cornerRadius = self.judgeButton1.mj_h * 0.5;
        self.judgeButton1.layer.borderColor = self.judgeButton1.titleLabel.textColor.CGColor;
        self.judgeButton1.layer.borderWidth = 1.0f;
    }
    if (self.lookforButton1) {
        self.lookforButton1.layer.masksToBounds = YES;
        self.lookforButton1.layer.cornerRadius = self.lookforButton1.mj_h * 0.5;
        self.lookforButton1.layer.borderColor = self.lookforButton1.titleLabel.textColor.CGColor;
        self.lookforButton1.layer.borderWidth = 1.0f;
    }
    if (self.scrollView) {
        self.scrollView.delegate = self;
    }
    if (self.headImageView1) {
        self.headImageView1.layer.masksToBounds = YES;
        self.headImageView1.layer.cornerRadius = self.headImageView1.mj_h * 0.5;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


#pragma mark --mark UIScrollViewDelegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGPoint offset = scrollView.contentOffset;
    CGFloat w = scrollView.mj_w;
    int index = (int)(offset.x / w);
    [self.paageControl setCurrentPage:index];
}

#pragma mark --mark EVENT

/**
 写评论

 @param sender sender
 */
- (IBAction)commentButtonClick:(UIButton *)sender {
    if (self.block) {
        self.block(CellCourseButtonClickTypeComment, sender);
    }
}

/**
 查看全部评论

 @param sender sender
 */
- (IBAction)lookForAllCommentsButtonClock:(UIButton *)sender {
    if (self.block) {
        self.block(CellCourseButtonClickTypeLookupAllComment, sender);
    }
}

/**
 展开更多

 @param sender sender
 */
- (IBAction)showMoreButtonClick0:(UIButton *)sender {
    if (self.block) {
        self.block(CellCourseButtonClickTypeShowMore, sender);
    }
}

/**
 更多金句

 @param sender sender
 */
- (IBAction)moreDetailButtonClick3:(UIButton *)sender {
    if (self.block) {
        self.block(CellCourseButtonClickTypeMoreSentence, sender);
    }
}


@end
